package com.rentong.cust.utils;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.rentong.cust.vo.ExportExcelDto;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.io.File;
import java.time.LocalDate;
import java.util.List;

public class ExportExcelService {

    /**
     * 导出 Excel 文件
     *
     * @param data     要导出的数据，List<ExportExcelDto>
     * @param filePath Excel 文件路径
     */
    public static void exportToExcel(List<ExportExcelDto> data, String filePath) {
        EasyExcel.write(new File(filePath))
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自动调整列宽
                .registerWriteHandler(new CustomWriteHandler(data)) // 自定义写入逻辑
                .sheet("维修记录")
                .doWrite(data);

        System.out.println("Excel 导出成功，路径：" + filePath);
    }




}
